package com.controllers
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.MouseEvent;

	public class MouseController extends EventDispatcher
	{
		protected var _clickFun:Function;
		protected var _downFun:Function;
		protected var _upFun:Function;
		public function MouseController(target:IEventDispatcher=null)
		{
			super(target);
			target.addEventListener(MouseEvent.CLICK,onMouseClick);
			target.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
			target.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
			_clickFun = new Function;
			_downFun = new Function;
			_upFun = new Function;
		}
		public function set clickFun(fun:Function):void{
			_clickFun = fun;
		}
		public function set downFun(fun:Function):void{
			_downFun = fun;
		}
		public function set upFun(fun:Function):void{
			_upFun = fun;
		}
		public function init(dispaly:IEventDispatcher):void{
			dispaly.addEventListener(MouseEvent.CLICK,onMouseClick);
			dispaly.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown);
			dispaly.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
		}
		protected function onMouseDown(e:MouseEvent):void{
			_downFun();
		}
		protected function onMouseClick(e:MouseEvent):void{
			_clickFun();
		}
		protected function onMouseUp(e:MouseEvent):void{
			_upFun();
		}
	}
}